package io.renren.modules.logisticstracking.service.impl;

import io.renren.modules.waybillorder.entity.WaybillOrderEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.logisticstracking.dao.LogisticsTrackingDao;
import io.renren.modules.logisticstracking.entity.LogisticsTrackingEntity;
import io.renren.modules.logisticstracking.service.LogisticsTrackingService;


@Service("logisticsTrackingService")
public class LogisticsTrackingServiceImpl extends ServiceImpl<LogisticsTrackingDao, LogisticsTrackingEntity> implements LogisticsTrackingService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<LogisticsTrackingEntity> logisticsTrackingEntityQueryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank((String)params.get("waybillno"))){
            logisticsTrackingEntityQueryWrapper.lambda().eq(LogisticsTrackingEntity::getWaybillno,params.get("waybillno"));
        }
        logisticsTrackingEntityQueryWrapper.lambda().orderByAsc(LogisticsTrackingEntity::getCreatetime);
        IPage<LogisticsTrackingEntity> page = this.page(
                new Query<LogisticsTrackingEntity>().getPage(params), logisticsTrackingEntityQueryWrapper);
        return new PageUtils(page);
    }

    @Override
    public List<LogisticsTrackingEntity> getAll(Long waybillno) {
        QueryWrapper<LogisticsTrackingEntity> logisticsTrackingEntityQueryWrapper = new QueryWrapper<>();
        logisticsTrackingEntityQueryWrapper.lambda().eq(LogisticsTrackingEntity::getWaybillno,waybillno).orderByDesc(LogisticsTrackingEntity::getCreatetime);
        return this.list(logisticsTrackingEntityQueryWrapper);
    }

}